Crate ptyprocess
source ·Expand description
A library provides an interface for a unix PTY/TTY.
It aims to work on all major Unix variants.
The library was developed as a backend for a https://github.com/zhiburt/expectrl.
If you’re interested in a high level operations may you’d better take a look at zhiburt/expectrl
.
Usage
use ptyprocess::PtyProcess;
use std::process::Command;
use std::io::{BufRead, Write, BufReader};
// spawn a cat process
let mut process = PtyProcess::spawn(Command::new("cat")).expect("failed to spawn a process");
// create a communication stream
let mut stream = process.get_raw_handle().expect("failed to create a stream");
// send a message to process
writeln!(stream, "Hello cat").expect("failed to write to a stream");
// read a line from the stream
let mut reader = BufReader::new(stream);
let mut buf = String::new();
reader.read_line(&mut buf).expect("failed to read a process output");
println!("line={}", buf);
// stop the process
assert!(process.exit(true).expect("failed to stop the process"))
Modules
Structs
- PtyProcess controls a spawned process and communication with this.
Enums
- Types of operating system signals
- Possible return values from
wait()
orwaitpid()
.
Functions
Type Definitions
- Nix’s main error type.